﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../../Script/boot.js" type="text/javascript"></script>
</head>
<body>
    <div style="width: 800px;">
        <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconcls="icon-add" onclick="add()">增加</a> 
                        <a class="mini-button" iconcls="icon-add" onclick="edit()">编辑</a> 
                        <a class="mini-button" iconcls="icon-remove" onclick="remove()">删除</a>
                    </td>
                    <td style="white-space: nowrap;">
                        <input id="key" class="mini-textbox" emptytext="请输入名称" style="width: 150px;" onenter="onKeyEnter" />
                        <a class="mini-button" onclick="search()">查询</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="datagrid1" class="mini-datagrid" style="width: 800px; height: 280px;" allowresize="true"
        url="AjaxService.aspx?method=SearchUsers" idfield="id" multiselect="true">
        <div property="columns">
            <!--<div type="indexcolumn"></div>        -->
            <div type="checkcolumn">
            </div>
            <div field="userName" width="120" headerAlign="center" allowSort="true">用户名</div>
            <div field="roleName" width="120" headerAlign="center" allowSort="true">用户角色</div>
            <div field="factoryName" width="120" headerAlign="center" >生产厂商</div>
            <div field="createDate" width="120" headerAlign="center" dateFormat="yyyy-MM-dd" allowSort="true">创建日期</div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();

        var grid = mini.get("datagrid1");
        grid.load();
        grid.sortBy("createDate", "desc");


        function add() {

            mini.open({
                url: bootPATH + "../Manage/User/UserWindow.htm",
                title: "新增商品", width: 600, height: 460,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function edit() {

            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: bootPATH + "../Manage/User/UserWindow.htm",
                    title: "编辑商品", width: 600, height: 460,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", id: row.id };
                        iframe.contentWindow.SetData(data);

                    },
                    ondestroy: function (action) {
                        grid.reload();

                    }
                });

            } else {
                alert("请选中一条记录");
            }

        }
        function remove() {

            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.id);
                    }
                    var id = ids.join(',');
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "AjaxService.aspx?method=RemoveUsers&id=" + id,
                        success: function (text) {
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            } else {
                alert("请选中一条记录");
            }
        }
        function search() {
            var key = mini.get("key").getValue();
            grid.load({ key: key });
        }
        function onKeyEnter(e) {
            search();
        }
      
    </script>
</body>
</html>
